﻿using System;
using System.Collections.Generic;

namespace ebcpatterns.rx
{
    public class ToStream<T>
    {
        private readonly T _endOfStreamValue;

        public ToStream() : this(default(T)) {}
        public ToStream(T endOfStreamValue)
        {
            _endOfStreamValue = endOfStreamValue;
        }

        public void Process(IEnumerable<T> values)
        {
            foreach (var v in values)
                NextValue(v);
            NextValue(_endOfStreamValue);
            EndOfStream();
        }

        public event Action<T> NextValue;
        public event Action EndOfStream = delegate { };
    }
}
